{extend name="shop/b2c/Member/base" /}
{block name="resources"}
<style type="text/css">
td{padding:10px;border: 1px Black; width:46px;}
table{background-color:#eeeeee;border:0;width:100%;}
.integral_title{display:block;font-size:18px;text-align:center;padding:20px;}
.user-right .tabmenu .tab li {border-bottom: 2px #ff6600 solid;} 
</style>
{/block}
{block name="main"}
<script>
	$(document).ready(function(){
		var max = parseInt($("input[name='amount']").attr("max"));		//最大余额
		var number = $("#number").text();								//可用积分
		var yz = false;													//验证条件
		var subscription = $("#subscription").val();					//兑换比例
		//点击进入积分兑换
		$("#extract").on("click",function(){
			number = $("#sum").text();
			$("#firstpage").hide();
			$("#secondpage").show();
		});
		//点击返回余额明细界面
		$("#extract2").on("click",function(){
			$("#firstpage").show();
			$("#secondpage").hide();
			$("input[name='amount']").val("");
		});
		//左侧菜单栏选中效果
		$("#qiye_point").addClass('curs');
		//选中积分提示效果
		$("input[name='amount']").on("keyup",function(){			
			 var getnumber = $("input[name='amount']").val();	//输入框中输入的积分	
			 if(getnumber.search(/[^\-?\d.]/g) == -1){
				var stringToNumber = parseFloat(getnumber);
				if(stringToNumber>0 && stringToNumber<=max){
					var result = subscription*stringToNumber;
					$(this).css("border","1px solid #ccc");
					$("#proving").text("兑换金额为¥"+result.toFixed(2)).css("color","red");	
					yz = true;
				}else{
					$(this).css("border","1px solid red");
					$("#proving").text("请填写一个0到"+number+"之间的数字").css("color","red");
					yz = false;
				}	
			}else{
				$(this).css("border","1px solid red");
				$("#proving").text("请输入正确的积分格式").css("color","red");
				yz = false;
			}  
		});
		$("input[name='submit']").on("click",function(){
			if(yz){
				$("#formsubmit").submit();
			}else{
				
				$("input[name='amount']").trigger("focus");
				return false;
			}
		});
});
</script>
	<input type="hidden" value="{$account}" id="subscription"/>
    <div class="user-right" >
    	<div class="box" id="firstpage">
<!--            <span class="integral_title" style="display:inline-block;"><b>{$shopname}积分操作明细(可用积分:<span id="sum">{$sum}</span>)</b></span> -->
           	<div class="interal_table" style="height:40px;">
                <span style="display:inline-block; float:left;font-size:16px;margin:10px;">
                {if condition="!isset($shopname)"}
                 	{$platform_shopname}
                {else /}
                	{$shopname}
                {/if}<span style="color:#989191;">(积分:<span id="sum">{$sum})</span></span>
                </span>
            </div> 
{if condition="$total_count neq ''"}
		<table>
            <tr align="center">
              <td>类别</td>              
              <td>数量</td>
              <td>描述</td>
              <td>时间</td>
            </tr>
            <tbody id="list_content" class="close-order">
			   {foreach $balances.data as $balance}
				<tr align="center">
				{switch name="$balance.from_type"}
				{case value="1"}	
					<td>积分减少</td>				
					<td style="color:red;font-size:14px;">-{$balance.number}</td>
				{/case}
				{case value="2"}	
					<td>积分增加</td>				
					<td style="color:green;font-size:14px;">+{$balance.number}</td>
				{/case}
				{case value="3"}	
					<td>积分兑换</td>				
					<td style="color:red;font-size:14px;">-{$balance.number}</td>
				{/case}
				{default/}
					<td>积分失踪</td>				
					<td style="color:red;font-size:14px;">+{$balance.number}</td>
				{/switch}
					<td>{$balance.text}</td>
					<td>{$balance.create_time}</td>
				</tr>
			{/foreach}
            </tbody>
          
          </table>
  {else/}
          <div>
              <div class="emptyFrame"> <i class="user_point"></i><span>您暂时还没有积分哦！</span> </div>
          </div>
       {/if}           
          
            {include file='shop/b2c/controlCommonPage'/}
        </div> 
        <div class="box" id="secondpage" style="display:none;">
        <div class="interal_table" style="height:40px;">
                <span style="display:inline-block; float:left;font-size:16px;margin:10px;">
                		会员积分
                </span>
                <span style="display:inline-block; float:right;font-size:14px;margin:10px;">
              	<a  class="main-color" id="extract2" style="color:red;">积分明细</a> | 
                 <a href="SHOP_MAIN/member/integral.html" class="table_manual" style="color:#000;">我的积分</a>
                 </span>
            </div> 
           <form name="formSurplus" method="post" action="SHOP_MAIN/member/exchange" id="formsubmit">
           <input type="hidden" name="shopid" value="{$shop_id}"> 
            <table width="100%" border="0" cellpadding="10" cellspacing="1" bgcolor="#eeeeee">
              <tr>
                <td width="10%" align="right">兑换积分数:</td>
                <td align="left">
                	<input type="text" name="amount" value="" class="deal" size="30" min="0" max="{$sum}" style="width:86px;border:1px solid #ccc;"/>
                	<span style="display:inline-block;" id="proving"></span>
                </td>
              </tr>
              <tr>
                <td width="10%" align="right"><span style="display:inline-block;">可用积分为<span id="number">{$sum}</span></span></td>
                <td align="left">兑换比例为1积分兑换{$account}元</td>
              </tr>
                <td colspan="2" align="center"><input type="hidden" name="surplus_type" value="1" />
                  <input type="hidden" name="act" value="act_account" />
                  <input type="submit" name="submit"  class="main-btn main-btn-large" value="兑换" />
                  </td>
              </tr>
            </table>
          </form>
		  </div>
</div>

{/block}